class LoginController < ApplicationController
	layout "board"

  def add_user
		@user = User.new(params[:user])
		if request.post? and @user.save
			flash[:notice] = "User #{@user.userName} created"
			@user = User.new
		end
  end

  def login
		session[:user_id] = nil
		if request.post?
			user = User.authenticate(params[:userName], params[:password])
			if user
				session[:user_id] = user.id
				redirect_to(:controller => "board", :action => "index", :id => user.userName)
			else
				flash[:notice] = "Invalid user/password combination"
				redirect_to(:action => :login)
			end
		end
	end

	def index
  end

  def delete_user
  end

  def list_users
  end



	def logout
		user = User.find_by_id(session[:user_id])
		if user
			reset_session
			redirect_to(:controller => "board", :action => "index", :id => user.userName)
		else
			redirect_to(:action => "login")
		end
	end
end
